<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: show_players.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

?>
<div id="joomleague">
<!-- Header with Project Name-->
<?php if ($showPlayers_config['show_project_heading'] == "1" OR $overall_config['show_project_heading'] == "1") { ?>
<div class="componentheading" <?php if ($showPlayers_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") echo 'style="float:left;"';?>><?php echo $htmlHelper->showTitle($joomleague, $overall_config['project_heading_type']); ?></div>
<!-- Druckfunktion -->
<?php if ($showPlayers_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") {
$htmlHelper->PrintIcon( $row, $params, false, '' );
};?>
<!-- Druckfunktion Ende -->
<?php } ?>
<!-- Header END -->

<!-- section header e.g. ranking, results etc. -->
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading"><?php echo _JL_PLAYERS_KADER;?> <?php echo $team->name;?> 
    <?php if ($showPlayers_config['show_team_shortform']==1) echo '[ '.$team->short_name.' ]' ;?></td>
	</tr>
</table>
<!-- section header END -->

<br />

<?php
if ( $showPlayers_config['show_team_logo'] == 1 ) 
{
  $picture = (is_null($teamtool->picture)) ? "components/com_joomleague/images/placeholders/placeholder_450.png" : $teamtool->picture;
  ?>   
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
    <tr>
      <td align="center"><img src="<?php echo _JOOMLA_JL_LIVE_SITE; ?>/<?php echo $picture;?>" alt="<?php  echo $team->name?>" title="<?php  echo $team->name?>" /></td>
    </tr>  
  </table>
  <?php 
} 

if( trim( $teamtool->description != "" ) ) 
{ 
  ?>
  <br />
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
    <tr class="sectiontableheader">
  		<td><?php echo _JL_PLAYERS_KADER_INFO;?></td>
  	</tr>
  </table>
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
    <tr>
        <td>
          <?php echo $teamtool->description;?>
        </td>
    </tr>  
  </table>
  <?php
} 
?>

<br /><br />
<?php 

// Display players
if ( count( $rows > 0 ) ) 
{ 
  ?>
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <?php
  $k = 0;
  $position = "";
  for ($i=0, $n=count( $rows ); $i < $n; $i++) 
  {
    $row = &$rows[$i];
    
    // Display position separator ?
    if ( $position != $row->position )
    {
      $position = $row->position;
      $k = 0;
      ?>
      <tr class="sectiontableheader">
        <td width="60%" colspan="<?php 
            echo ((isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) ? '6' : '5'); ?>
            "><?php echo $position; ?>
        </td>
        <?php
        if ($showPlayers_config['show_stats']==1) { 
          if ( $overall_config['use_jl_substitution'] == 1 ) {
            if ( $showPlayers_config['show_games_played'] ) {
              ?>
              <td align="center"><img src="<?php echo JL_TEMPLATE_FOLDERS_URL.'/images/shirt.png';?>" height="20" alt="<?php
                echo _JL_PLAYER_PLAYED;
                ?>" />
              </td>
              <?php
            }
            if ( $showPlayers_config['show_substitution_stats'] ) {
              ?>
              <td align="center"><img src="<?php echo JL_TEMPLATE_FOLDERS_URL.'/images/in.png';?>" alt="<?php echo _JL_PLAYER_IN;?>" /></td>
              <td align="center"><img src="<?php echo JL_TEMPLATE_FOLDERS_URL.'/images/out.png';?>" alt="<?php echo _JL_PLAYER_OUT;?>" /></td>
              <?php
            }
   			  }
   			  if (isset($PosEventtypes[$row->position_id]) && $overall_config['use_jl_events']) if ( count($PosEventtypes[$row->position_id]) )
   			  {
            foreach ($PosEventtypes[$row->position_id] AS $eventtype) {
              echo '<td align="center"><img src="'._JOOMLA_JL_LIVE_SITE.'/images/joomleague/event_icons/'.$eventtype->icon.'" alt="'.$eventtype->name.'" title="'.$eventtype->name.'" align="top" hspace="2" /></td>';
            }
   			  }
   			}
      	?>
      </tr>
      <?php
    }
    
    // Display players rows
    ?>
    <tr class="<?php echo ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2'; ?>">
      <td width="30" align="center">
        <?php
        if ( $showPlayers_config['show_player_numbers'] == 1 ) {
        	if ($showPlayers_config['player_numbers_pictures']==1 && function_exists('imagecreatefrompng')) { ?>
          <img src="<?php echo JL_TEMPLATE_FOLDERS_URL;?>/images/shirt.php?text=<?php echo ($row->position_number!=0) ? $row->position_number : '';?>" alt="<?php echo $row->position_number;?>" />
          <?php
        	}
        	else { echo ($row->position_number!='') ? $row->position_number : '&nbsp;'; }
        }
        else echo '&nbsp;'; ?>
      </td>
      <td width="40" align="center" nowrap="nowrap">
        <?php 
        if ( $showPlayers_config['show_player_icon'] == 1 ) 
        {
          // look for picture in Playertool first
		      if ( $row->picture && file_exists( _JOOMLA_JL_PATH.'/'.$row->picture ) ) {
		         $picture = _JOOMLA_JL_LIVE_SITE.'/'.$row->picture;
		      }
		      // otherzise, look for defqult picture on player objet
		      else if ( $row->default_picture && file_exists( _JOOMLA_JL_PATH.'/'.$row->default_picture ) ) {
		        $picture = _JOOMLA_JL_LIVE_SITE.'/'.$row->default_picture;
		      }
		      else {
		        $picture = null;
		      }
		      
		      if ( $picture ) 
		      {
            $Thumb = new PowerThumb();
            $Thumb->setSrc( $picture );
            $Thumb->setDescription( $row->description );
            $Thumb->setAlt( $row->firstname." ".$row->lastname );
            $Thumb->setMaxHeight( 30 );
            $Thumb->setAmpliationLink( false) ;
            //$Thumb->setFilter("gray");
            $Thumb->create();
          }
        }
        ?>
      </td>
      <td style="width:20%;">
        <?php 
        if ( $showPlayers_config['link_player'] == 1 ) 
        { 
          ?>
          <a href="<?php echo sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showPlayer&amp;p=$joomleague->id&amp;pid=$row->pid".JL_ITEMID_SUFFIX);?>">
          <?php printf("<i>%s %s</i>",$row->firstname,$row->lastname);?></a>
          <?php 
        } 
        else {
          printf("<i>%s %s</i>",$row->firstname,$row->lastname);
        }
        ?>
      </td>
      <td width="5%" align="left">
      	<?php 
        if( $row->injury > 0 && $row->injury_end > $joomleague->current_round ) {
          echo '<img src="'.JL_TEMPLATE_FOLDERS_URL.'images/injured.gif" alt="" />';
        }
        ?>
      	<?php 
        if( $row->suspension > 0 && $row->suspension_end > $joomleague->current_round) {
          echo '<img src="'.JL_TEMPLATE_FOLDERS_URL.'images/suspension.gif" alt="" />';
        }
        ?>    
      </td>     
      <td style="width:16px;" nowrap="nowrap" align="left">
        <?php
        if ( $row->nation )
        {
          $thiscountry = new Country($database);
          $thiscountry->load($row->nation);
          echo $thiscountry->getFlag();
        }
        else {
          print '&nbsp;';
        }
        ?>
      </td>
      <?php 
      if ( isset($showPlayers_config['show_birthday']) 
          && $showPlayers_config['show_birthday'] == 1) 
      {
        ?>
        <td width="10%" nowrap="nowrap" align="left">
        <?php printf("%s (%s)", mbiFormatDate($row->birthday,_JL_PLAYERS_BIRTHDATE_DATE),
        getAge( $row->birthday, $joomleague->start_date )); ?>
        </td>
        <?php
      }
      if ($showPlayers_config['show_stats']==1) {
        if ( $overall_config['use_jl_substitution'] ) {
          $query = "SELECT count(mp.id) as played, sum(mp.came_in) as sub_in, sum(mp.out = 1) AS sub_out
                     FROM #__joomleague_match_players AS mp LEFT join #__joomleague_matches AS m ON mp.match_id = m.match_id 
                     WHERE mp.player_id = '".$row->player_id."' AND m.project_id = '".$joomleague->id."'";
          $database->setQuery($query);
          $inoutstat = $database->loadObjectList();
          if ($inoutstat[0]->played > 0) {
            if ( $showPlayers_config['show_games_played'] ) {
              echo '<td align="center" nowrap="nowrap">'.$inoutstat[0]->played;
              if (isset($overall_config['use_jl_substitution']) && $overall_config['use_jl_substitution'] == 1) {
               echo ' <acronym title="'._JL_STARTING_ROSTERS.'">('
               .(($inoutstat[0]->played - $inoutstat[0]->sub_in > 0) ? $inoutstat[0]->played - $inoutstat[0]->sub_in : '-')
               .')</acronym>';
              }              
              echo '</td>';
            }
            if ( $showPlayers_config['show_substitution_stats'] ) {
               echo '<td align="center">'.(($inoutstat[0]->sub_in > 0) ? $inoutstat[0]->sub_in : '-').'</td>';
               echo '<td align="center">'.(($inoutstat[0]->sub_out > 0) ? $inoutstat[0]->sub_out : '-').'</td>';
             }
          }
          else {
            if ( $showPlayers_config['show_games_played'] ) {
              echo '<td align="center">-</td>';
            }
            if ( $showPlayers_config['show_substitution_stats'] ) {
              echo '<td align="center">-</td><td align="center">-</td>';
            }
          }
        }
        if (isset($PosEventtypes[$row->position_id]) && $overall_config['use_jl_events']) if ( count( $PosEventtypes[$row->position_id] ) )
        {
          foreach ($playerStats[$row->id] AS $eventId => $stat) 
          {
    	      	echo '<td align="center">';
    	      	echo ($stat!=""&&$stat>0)?$stat:"-";
    	      	echo '</td>';
    	    }
        }
	 }?>
    </tr>
<?php
    $k = 1 - $k;
  }
?>

</table>
<br /><br />

<?php 
// Display Staff
if ( count( $stafflist ) > 0) 
{ 
  ?>
  <table width="100%" class="contentpaneopen">
  	<tr>
  		<td class="contentheading"><?php echo _JL_PLAYERS_STAFF;?> <?php echo $team->name;?> 
      <?php if ($showPlayers_config['show_team_shortform']==1) echo '[ '.$team->short_name.' ]' ;?></td>
  	</tr>
  </table><br />
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
    <tr class="sectiontableheader">
      <td width="60%" 
          colspan="<?php echo ((isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) ? '6' : '5'); ?>">
            <?php echo _JL_PLAYERS_STAFFPOSITIONS; ?>
      </td>
      <td><?php echo _JL_PLAYERS_FUNCTION;?></td>
    </tr>
  <?php
  $k = 0;
  for ($i=0, $n=count( $stafflist ); $i < $n; $i++) {
    $row = &$stafflist[$i];
?>
  <tr class="<?php echo ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2'; ?>">
    <td width="30" align="center"> </td>
    <td width="40" align="center" nowrap="nowrap">
<?php if ($showPlayers_config['show_player_icon']==1) { 
$picture = ($row->picture!=''&&!is_null($row->picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$row->picture)) ? $row->picture : $row->default_picture;
if ($picture!=''&&!is_null($picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$picture)) {
$Thumb = new PowerThumb();
$Thumb->setSrc($picture);
$Thumb->setDescription($row->description);
$Thumb->setAlt($row->firstname." ".$row->lastname);
$Thumb->setMaxHeight(30);
$Thumb->setAmpliationLink(false);
//$Thumb->setFilter("gray");
$Thumb->create();
}
?>
<?php } ;?>
</td>
    <td style="width:20%;">
    <?php if ($showPlayers_config['link_player']==1) { ;?>
    <a href="<?php echo sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showTeamstaff&amp;p=$joomleague->id&amp;pid=$row->id&amp;tsid=$row->teamstaff_id".JL_ITEMID_SUFFIX);?>">
    <?php printf("<i>%s %s</i>",$row->firstname,$row->lastname);?></a>
    <?php } 
    else printf("<i>%s %s</i>",$row->firstname,$row->lastname);?>
    </td>
    <td width="5%">&nbsp;</td>
    <td style="width:16px;" nowrap="nowrap" align="left">
      <?php
      if ( $row->nation )
      {
        $thiscountry = new Country($database);
        $thiscountry->load($row->nation);
        echo $thiscountry->getFlag();
      }
      else {
        print '&nbsp;';
      }
      ?>
    </td>
    <?php
    if ( isset($showPlayers_config['show_birthday']) 
        && $showPlayers_config['show_birthday'] == 1) 
    { 
      ?>
      <td width="10%" nowrap="nowrap" align="left">
      <?php
      printf( "%s (%s)", 
             mbiFormatDate( $row->birthday,_JL_PLAYERS_BIRTHDATE_DATE ),
             getAge( $row->birthday, $joomleague->start_date ) ); 
      ?>
      </td>
      <?php
    }
    ?>
    <td><?php print ($row->position); ?></td>
<?php
    $k = 1 - $k;
  }
?>   
</table>

<?php 
}
};?>

<!-- Print Button START -->
<?php if ($showPlayers_config['show_back_button'] > 0 OR $overall_config['show_back_button'] > 0) {;?>
<?php if ($showPlayers_config['show_back_button'] == "1" OR $overall_config['show_back_button'] == "1") echo '<div align="left">'; else echo '<div align="right">';?>
<?php
$params = & new mosParameters( '' );
$params->def( 'back_button', true );
$params->def( 'popup', false );
mosHTML::BackButton( $params );
  echo "</div>";
};?>
<!-- Print Button END -->
</div>